package com.example.lesson_10_25.webMVC;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * @PACKAGE_NAME: com.example.lesson_10_25.webMVC
 * @NAME: MyInterceptor
 * @USER: jiang000
 * @DATE: 2023/11/22
 **/
@Component
public class MyInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        // 在Controller方法之前处理
        System.out.println("preHandle被调用");
        return true; // 如果返回false, 停止流程，api不会被调用
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("postHandle被调用");
    }
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        // 在整个请求结束后调用
        System.out.println("afterCompletion被调用");
    }
}
